package com.sf.dlb.jpa.repository;

import com.sf.dlb.jpa.model.AppVersionInfo;
import com.sf.dlb.jpa.model.UserDlbRecordInfo;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * 用户dlb流水表 Repository
 *
 * Created by jing.tan on 2018/5/21.
 */
@Repository
public interface UserDlbRecordRepository extends JpaRepository<UserDlbRecordInfo, Long> {

    /**
     * 每日挖dlb
     * @param userId
     * @param currentTime
     * @param delFlag
     * @return
     */
    @Query(value = "select sum(cast(a.dlb_number as decimal(18,3))) from user_dlb_record a where a.user_id=?1 and DATE_FORMAT(a.create_date,'%Y-%m-%d')=?2 and a.dlb_type=?3 and a.del_flag=?4 ",nativeQuery = true)
    Double findByEveryDayDlb(String userId, String currentTime, String dlbType, String delFlag);

    /**
     * 查询用户流水
     * @return
     */
    List<UserDlbRecordInfo> findByUserIdAndDelFlagOrderByCreateDateDesc(String userId, String delFlag);
    /**
     * 查询用户流水-source
     * @return
     */
    List<UserDlbRecordInfo> findByUserIdAndSourceAndDelFlag(String userId,String source,String delFlag);
    /**
     * 查询用户流水-分页
     * @return
     */
    Page<UserDlbRecordInfo> findByUserIdAndDelFlag(String userId, String delFlag, Pageable pageable);
}